package com.example.minefieldkeepercloud.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.example.minefieldkeepercloud.R;
import com.example.minefieldkeepercloud.bean.BrandlAndModelBean;
import com.king.base.adapter.ViewHolderAdapter;
import com.king.base.adapter.holder.ViewHolder;

import java.util.ArrayList;
import java.util.List;

public class GridBrandAdapter extends ViewHolderAdapter<BrandlAndModelBean.DataBean> {
    private Context context;
    private int selectedPos=-1;//选中的id 没有为-1
    private List<BrandlAndModelBean.DataBean> listData_new=new ArrayList<>();
    public GridBrandAdapter(Context context, List<BrandlAndModelBean.DataBean> listData) {
        super(context, listData);
        this.context = context;
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, BrandlAndModelBean.DataBean dataBean, int position) {
        return inflate(R.layout.adapter_brand);
    }

    @Override
    public void bindViewDatas(ViewHolder holder, BrandlAndModelBean.DataBean bean, final int position) {
        holder.setText(R.id.tv_content,bean.getBrandlName());
        if (position==selectedPos)
        {
            //选中的项
            ((TextView)holder.getView(R.id.tv_content)).setTextColor(context.getResources().getColor(R.color.white));
            ((TextView)holder.getView(R.id.tv_content)).setBackgroundResource(R.drawable.menu_select_bg);
        }else
        {
            ((TextView)holder.getView(R.id.tv_content)).setTextColor(context.getResources().getColor(R.color.black));
            ((TextView)holder.getView(R.id.tv_content)).setBackgroundResource(R.drawable.menu_noselect_bg);
        }
    }

    /**
     * 展开
     * @param bln_show
     */
    public void isShow(boolean bln_show,List<BrandlAndModelBean.DataBean> listData)
    {
        if(bln_show)
        {
            listData_new.clear();
            if(listData.size()>3)
            {
                for (int i=0;i<3;i++)
                {
                    listData_new.add(listData.get(i));
                }
                setListData(listData_new);
                notifyDataSetChanged();
            }
            else
            {
                listData_new.addAll(listData);
                setListData(listData_new);
                notifyDataSetChanged();
            }
        }
        else
        {
            setListData(listData);
            notifyDataSetChanged();
        }
    }
    /**
     * 设置选中
     * @param i
     */
    public void setSelected(int i)
    {
        selectedPos=i;
        notifyDataSetChanged();
    }

    /**
     * 设置选中id
     */
    public int getSelectedPos() {
        return selectedPos;
    }
}
